<?php


namespace Tbf\Component\Image\Tests;


use Symfony\Component\Yaml\Yaml;
use Tbf\Bundle\TestBundle\TestSuite\TbfTestCase;
use Tbf\Component\Image\FontDraw;
use Tbf\Component\Image\ImageFunction;

class FontDrawTest extends TbfTestCase{
    function testIsInRectangle(){
        $test_cases = Yaml::parse(<<<'YML'
- {x:0,y:0,text:abc,size:12,r_x:0,r_y:0,r_h:1000,r_w:1000,ret:true}
- {x:-1,y:0,text:abc,size:12,r_x:0,r_y:0,r_h:1000,r_w:1000,ret:false}
- {x:0,y:0,text:abc,size:12,r_x:0,r_y:0,r_h:11,r_w:1000,ret:false}
- {x:0,y:0,text:abc,size:12,r_x:0,r_y:0,r_h:12,r_w:1000,ret:true}
- {x:0,y:0,text:abc,size:12,r_x:0,r_y:0,r_h:12,r_w:27,ret:true}
YML
);
        foreach($test_cases as $name=>$test_case){
            $draw = new FontDraw();
            $ret = $draw->setFontfile(ImageFunction::getEnFontPath())
                ->setText($test_case['text'])
                ->setSize($test_case['size'])
                ->setX($test_case['x'])
                ->setY($test_case['y'])
                ->isInRectangle(ImageFunction::newRectangle()
                    ->setX($test_case['r_x'])
                    ->setY($test_case['r_y'])
                    ->setHeight($test_case['r_h'])
                    ->setWidth($test_case['r_w'])
                );
            $this->assertEquals($test_case['ret'],$ret,sprintf('fail at testcase :%s',$name));
        }
    }
}